﻿using Microsoft.SharePoint;
using Microsoft.SharePoint.Utilities;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace WindStyle.SPCalendar
{
    public class DateRange
    {
        public DateTime StartDate { get; set; }
        public EndOption End { get; set; }

        public DateRange()
        {
            this.StartDate = DateTime.Today;
            this.End = new EndOption();
        }

        public string ToXml(SPRegionalSettings regionalSettings)
        {
            switch (this.End.Type)
            {
                case EndType.ByInstances:
                    return "<repeatInstances>" + this.End.Instances + "</repeatInstances>";
                case EndType.ByDate:
                    return "<windowEnd>" + SPUtility.CreateISO8601DateTimeFromSystemDateTime(regionalSettings.TimeZone.LocalTimeToUTC(this.End.Date)) + "</windowEnd>";
                default:
                    return "<repeatForever>FALSE</repeatForever>";
            }
        }
    }
}
